package com.k2data.k2app.consumer;

import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @author lidong9144@163.com 17-4-26.
 */
@Log4j2
@Component
public class AppStartupEvent implements ApplicationListener<ContextRefreshedEvent> {

    private final KafkaService kafkaService;

    @Autowired
    public AppStartupEvent(KafkaService kafkaService) {
        this.kafkaService = kafkaService;
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        try {
            this.kafkaService.init();
            this.kafkaService.consumeTopic();
        } catch (Exception e) {
            log.error("", e);
        }
    }

}
